﻿-- =============================================
-- Author:  <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[UserSubmitListing]
  @Name nvarchar(50)='',
  @Phone nvarchar(50)='',
  @Email nvarchar(50)='',
  @Company nvarchar(50)='',
--  @UserID bigint = 1,
  @Price nvarchar(50)='',
  @Address nvarchar(200)='',
  @Remark nvarchar(200)='',
  @SubmissionType nvarchar(10)='Sale',
  @URL1 varchar(500)='',
  @PhotoId1 varchar(50)='',
  @URL2 varchar(500)='',
  @PhotoId2 varchar(50)='',
  @URL3 varchar(500)='',
  @PhotoId3 varchar(50)='',   
  @RetID varchar(50) OUTPUT
AS
BEGIN

 SET NOCOUNT ON;
-- INSERT QUERY INFO INTO Mobile_UserQueryTransact
DECLARE @ID uniqueidentifier = NEWID()


INSERT INTO Mobile_ListingSubmission(
[ID],[Name],[Phone],[Email],[Company],[Price],[Address],[Remark],[SubmissionType])
VALUES (@ID,@Name,@Phone,@Email,@Company,@Price,@Address,@Remark,@SubmissionType);

SET @RetID = convert(nvarchar(50), @ID);

IF @URL1 != '' AND @URL1 !='0'
 INSERT INTO AW_Picture([PictureId],[CreateDate],[PropertyId],[Picture],[PhotoId],[LargeUrl],[MediumUrl],[SmallUrl],[pictureURL])
 VALUES (NEWID(),GETDATE(),@RetID,@PhotoId1+'.jpg',@PhotoId1,@URL1,@URL1,@URL1,@URL1);
 
IF @URL2 != '' AND @URL2 !='0'
 INSERT INTO AW_Picture([PictureId],[CreateDate],[PropertyId],[Picture],[PhotoId],[LargeUrl],[MediumUrl],[SmallUrl],[pictureURL])
 VALUES (NEWID(),GETDATE(),@RetID,@PhotoId2+'.jpg',@PhotoId2,@URL2,@URL2,@URL2,@URL2);
IF @URL3 != '' AND @URL3 !='0'
 INSERT INTO AW_Picture([PictureId],[CreateDate],[PropertyId],[Picture],[PhotoId],[LargeUrl],[MediumUrl],[SmallUrl],[pictureURL])
 VALUES (NEWID(),GETDATE(),@RetID,@PhotoId3+'.jpg',@PhotoId3,@URL3,@URL3,@URL3,@URL3);

SELECT @RetID as N'@RetID'
RETURN 1; 
END
